package com.treeroot.treenet;

import com.treeroot.treenet.enums.ProtocolTypeMenu;
import com.treeroot.treenet.strategy.ProtocolStrategyContext;
import lombok.extern.slf4j.Slf4j;

/**
 * Description: 树网应用
 * Create By TreeRoot
 * Create Time: 2025/06/01 08:56
 * Class Name: TreeNetApplication
 *
 * @author TreeRoot
 */

@Slf4j
public class TreeNetApplication {
    private final ProtocolStrategyContext protocolStrategyHandlerContext = ProtocolStrategyContext.getInstance();

    public static void main(String[] args) {
        System.out.println("Hello TreeNet!");

        // 启动心跳线程
        Thread heartbeatThread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    Thread.sleep(100);
                    log.info("Heartbeat...");
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt(); // 重设中断标志
                    break;
                }
            }
        });
        // 设置为守护线程，不阻止程序退出
        heartbeatThread.setDaemon(true);
        heartbeatThread.start();

        new TreeNetApplication().hello();
    }
    void hello() {
        protocolStrategyHandlerContext.execute(ProtocolTypeMenu.getByValue(ProtocolTypeMenu.TCP.getValue()));
    }
}